package net.yambal.RTM.Method
{
	import net.yambal.RTM.Items.RTMTimezone;
	import net.yambal.RTM.Items.RTMTransaction;
	import net.yambal.RTM.RestWrapper.RestManager;
	import net.yambal.RTM.RestWrapper.RestService;
	import net.yambal.RTM.Utilty.RTMDateUtil;
	
	public class Time
	{
		public function Time()
		{
		}
		
		/**
		 * 望ましいtimezoneで指定された時間を返します。
		 **/
		public function convert(api_key:String, shared_secret:String, auth_token:String, to_timezone:RTMTimezone, from_timezone:RTMTimezone, time:Date = null):void{
			if(time == null){
				time = new Date();
			}
			
			var p:Object = new Object();
			p.api_key = api_key;
			p.to_timezone = to_timezone.id;
			p.auth_token = auth_token;
			if(from_timezone){
				p.from_timezone = from_timezone.id;
			}
			p.time = RTMDateUtil.to8601(time);
			trace(p.time);
			
			var RM:RestManager = new RestManager();
			RM.doMethod(RestService.METHOD_TIME_CONVERT, p,this.onConvert, this.onFaultConvert, false, shared_secret);
		}
		
		private function onFaultConvert(code:Number, massage:String, ro:Object):void{
			trace(code);
			trace(massage);
		}
		
		private function onConvert(result_xml:XML, ro:Object, t:RTMTransaction):void{
			trace(result_xml);
		}
		
		/**
		 * 解析された入力のために、UTCにおいて、時間を返します。
		 **/
		public function parse(api_key:String, text:String, timezone:RTMTimezone = null, dateformat:int = 1):void{
			var p:Object = new Object();
			p.api_key = api_key;
			p.text = text;
			
			var RM:RestManager = new RestManager();
			RM.doMethod(RestService.METHOD_TIME_PARSE, p, this.onParce, this.onFaultParse, false);
		}
		
		private function onFaultParse(code:Number, massage:String, ro:Object):void{
			trace(code);
			trace(massage);
		}
		
		private function onParce(result_xml:XML, ro:Object, t:RTMTransaction):void{
			trace(result_xml);
		}

	}
}